package alt.djudge.frontend.server.models;

import org.hibernate.criterion.Order;

import alt.djudge.frontend.server.Deployment;
import alt.djudge.frontend.server.datatypes.AbstractEntry;


public class DBAbstractor<T extends AbstractEntry>
{
	final ModelSettings<T> settings;
	
	public DBAbstractor(final ModelSettings<T> settings)
	{
		this.settings = settings;
	}
	
	public CoreInterface<T> getModel()
	{
		if (Deployment.isGAE())
			return
				new AbstractBigtableModelCore<T>()
				{
					@Override
					protected Class<T> getEntryClass()
					{
						return settings.getEntryClass();
					}

					@Override
					protected Order getOrdering()
					{
						return settings.getOrdering();
					}					
				};
		else
			return 
				new AbstractDBModelCore<T>()
				{
        			@Override
        			protected Class<T> getEntryClass()
        			{
        				return settings.getEntryClass();
        			}
        
        			@Override
        			protected Order getOrdering()
        			{
        				return settings.getOrdering();
        			}
				};
	}
}
